package dao;

import pojo.Author;
import util.JDBCUtil;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.jar.JarEntry;

/**
 * @author 郝雷蒙
 * @Description
 * @date 2020/11/10 12:18
 */
public class AuthorDaoImpl implements AuthorDao{
    @Override
    public List<Author> selectAllAuthors() {
        List<Author> authors = new ArrayList<>();

        String sql = "select * from author";

        JDBCUtil jdbcUtil = new JDBCUtil();

        ResultSet resultSet = jdbcUtil.excuteQuery(sql);

        try {
            while(resultSet.next()) {
               Author author = new Author();

               author.setAuthorId(resultSet.getInt("authorId"));
               author.setAuthorName(resultSet.getString("authorName"));
            }

            return authors;
        } catch (SQLException e) {
            e.printStackTrace();

            return null;
        } finally {
            jdbcUtil.close();
        }
    }
}